import {
  getUsers,
  addUsers,
  updateUsersState,
  getUsersById,
  updateUserInfo,
  deleteUserInfo,
  updateUserRole,
} from "@/api/users";

// 状态
const state = {
  usersData: {},
  usersDataById: {},
};
// 修改状态
const mutations = {
  setUsers(state, payload) {
    state.usersData = payload;
    // console.log(state.usersData);
  },
  setUsersDataById(state, payload) {
    state.usersDataById = payload;
    // console.log(state.usersDataById);
  },
};
// 执行异步
const actions = {
  //获取用户列表
  async getUsers(context, data) {
    const res = await getUsers(data);
    // console.log(res);
    context.commit("setUsers", res);
  },
  async addUsers(context, data) {
    console.log(data);
    await addUsers(data);
  },
  async updateUsersState(context, data) {
    console.log(123, data);
    await updateUsersState(data.uId, data.type);
  },
  async getUsersById(context, id) {
    const res = await getUsersById(id);
    // console.log(res);
    context.commit("setUsersDataById", res);
  },
  async updateUserInfo(context, data) {
    // console.log(data);
    await updateUserInfo(data);
  },
  async deleteUserInfo(context, id) {
    await deleteUserInfo(id);
  },
  async updateUserRole(context, data) {
    console.log(data);
    await updateUserRole(data);
  },
};
export default {
  namespaced: true,
  state,
  mutations,
  actions,
};
